/**
 * 输入框获取焦点，提示信息列背影样式修改为labbg_normal，提示文本内容显示
 * @param tdId 提示信息列ID
 * @param spanId 提示文本内容描述对象ID
 */
function chgPwdInputOnFocusListener(tdId, spanId) {
    var tdObj = document.getElementById(tdId);
    if(tdObj) {
        tdObj.className = "labbg_normal";
    }
    
    var spanObj = document.getElementById(spanId);
    if(spanObj) {
        spanObj.style.display = "block";
        spanObj.innerHTML = "密码由6-16位半角字符(字母、数字、符号)组成，区分大小写";
    }
}

String.prototype.trim = function(){
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
};

/**
 * 密码输入框失去焦点，提示信息列背影样式修改，提示文本内容修改
 * 同时对输入的密码进行校验，如果校验有误则显示错误提示信息
 * 
 * @param inputObj 输入对象
 * @param tdId 信息提示列ID
 * @param descSpanId 描述信息Span ID
 * @param errInfoSpanId 错误提示信息Span ID
 */
function lostFocusInputListener(inputObj, tdId, descSpanId) {
	var result = false;
	
    var inputValue = inputObj.value;
    if(inputValue != "") {
    	inputValue = inputValue.trim();
    	inputObj.value = inputValue;
    }
    
    var tdIdObj = document.getElementById(tdId);
    var descSpanidObj = document.getElementById(descSpanId);
    
    descSpanidObj.style.display = "none";
    
    var chkRsObj = chkPwd(inputValue);
    
    // 校验有误
    if(!chkRsObj.result) {
    	tdIdObj.className = "labbg_err";
    	descSpanidObj.style.display = "block";
    	descSpanidObj.innerHTML = chkRsObj['info'];
    	
    } else {
    	// 校验通过
    	tdIdObj.className = "";
    	descSpanidObj.style.display = "none";
    	descSpanidObj.innerHTML = "";
    	
    	result = true;
    }
    
    return result;
}

/**
 * 
 * @param inputObj 输入对象
 * @param tdId 信息提示列ID
 * @param newPwdId 第一个密码输入框
 * @param descSpanId 描述信息Span ID
 * @param errInfoSpanId 错误提示信息Span ID
 */
function lostFocusConfirmInputListener(inputObj, tdId, newPwdId, descSpanId) {
	var chRs = lostFocusInputListener(inputObj, tdId, descSpanId);
	if(chRs) {
		// 判断两次密码是否相等 
		var secPwd = inputObj.value;
		var newPwdIdObj = document.getElementById(newPwdId);
		var firPwd = newPwdIdObj.value.trim();
		newPwdIdObj.value = firPwd;
		
		var tdIdObj = document.getElementById(tdId);
		var descSpanIdObj = document.getElementById(descSpanId);
		if(secPwd != firPwd) {
			tdIdObj.className = "labbg_err";
			descSpanIdObj.style.display = "block";
			descSpanIdObj.innerHTML = "两次输入的密码不一致，请重新输入";
		} else {
	    	// 校验通过
	    	tdIdObj.className = "";
	    	descSpanidObj.style.display = "none";
	    	descSpanidObj.innerHTML = "";
	    }
	}
}

/**
 * 密码校验 
 * @param passwordValue
 * @returns {___resultObj0}
 */
function chkPwd(passwordValue) {
	var resultObj = new Object();
	resultObj['result'] = false;
	
	// 密码不能为空
	if(passwordValue == "" || passwordValue.length < 6 || passwordValue.length > 16) {
		resultObj['info'] = "密码长度不正确，应为6~16个字符 ";
		return resultObj;
	}
	
	resultObj.result = true;
	return resultObj;
}
